class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
from typing import *
class Solution:
    def reverseOddLevels(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
        
        def reverse(left:Optional[TreeNode],right:Optional[TreeNode],flag):
            if left is None:
                return root
            if flag == 0:
                left.val ,right.val = right.val,left.val
            
            reverse(left.left,right.right,flag ^ 1)
            reverse(left.right,right.left,flag ^ 1)

        reverse(root.left,root.right,0)

        return root
    
